package com.cn.por.auto.datasource.controller;
import com.cn.por.auto.datasource.dto.DataSourceConfigADTO;
import com.cn.por.auto.datasource.entity.DataSourceConfigADO;
import cn.hsa.base.web.vo.PageResultData;
import cn.hsa.base.web.BaseController;
import cn.hsa.base.web.vo.WrapperResponse;
import com.cn.por.auto.datasource.service.DataSourceConfigAService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * <p>数据源管理控制器</p>
 * @author xx
 * @since 2024-11-02
 */
@RestController
@RequestMapping("/web/datasource")
@Api(tags = "数据源管理")
public class DataSourceConfigAController extends BaseController  {

    @Autowired
    private DataSourceConfigAService dataSourceConfigAService;

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public WrapperResponse<DataSourceConfigADTO> addDataSourceConfigA(@RequestBody DataSourceConfigADTO dataSourceConfigADTO){
      DataSourceConfigADTO result = dataSourceConfigAService.add(dataSourceConfigADTO);
      return WrapperResponse.success(result);
    }
    

    @PostMapping("/edit")
    @ApiOperation(value = "修改")
    public WrapperResponse<DataSourceConfigADTO> updateDataSourceConfigA(@RequestBody DataSourceConfigADTO dataSourceConfigADTO){
      DataSourceConfigADTO result = dataSourceConfigAService.update(dataSourceConfigADTO);
      return WrapperResponse.success(result);
    }
    

    @GetMapping("/delete")
    @ApiOperation(value = "作废")
    public WrapperResponse<Boolean> deleteDataSourceConfigA(@RequestParam String id){
      Boolean result = dataSourceConfigAService.delete(id);
      return WrapperResponse.success(result);
    }
    

    @GetMapping("/item")
    @ApiOperation(value = "获取")
    public WrapperResponse<DataSourceConfigADTO> getDataSourceConfigA(String id){
      DataSourceConfigADTO result = dataSourceConfigAService.get(id);
      return WrapperResponse.success(result);
    }
    

    @PostMapping("/page")
    @ApiOperation(value = "获取分页")
    public WrapperResponse<PageResultData<DataSourceConfigADTO>> getPageDataSourceConfigA(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestBody DataSourceConfigADTO dataSourceConfigADTO){
      PageResultData<DataSourceConfigADTO> result = dataSourceConfigAService.getPage(pageNo,pageSize,dataSourceConfigADTO);
      return WrapperResponse.success(result);
    }

    @GetMapping("/getList")
    @ApiOperation(value = "获取所有数据源配置信息")
    public WrapperResponse<List<DataSourceConfigADO>> getList(){
        return WrapperResponse.success(dataSourceConfigAService.getSourceList());
    }
}